// JavaScript Document
define(function (require, exports, module) {
	///alert("TabController");
	
	var FocusList=require("FocusList");
	var FocusListItem=require("FocusListItem");
	
	var TabController=function(selector,controlMethod,focusNum){
		this.element=$(selector).get(0);
		
		if(!controlMethod){
			controlMethod="click";	
		}
		var self=this;
		this.controlList=new TabController.ControlList(this.element.children[0],controlMethod,function(focusNum){self.focusControl(focusNum);});
		this.contentList=new TabController.ContentList(this.element.children[1]);
		if(typeof(focusNum)!="undefined"){
			this.focusControl(focusNum);
		}
	};
	TabController.prototype.init=function(){}
	TabController.prototype.focusControl=function(focusNum){
		this.controlList.focusControl(focusNum);
		this.contentList.focusControl(focusNum);
	};
	//TabControlList
	TabController.ControlList=function(element,controlMethod,parent_focusControl){
		this.element=element;
		this.total=this.element.children.length;
		this.parent_focusControl=parent_focusControl;
		var self=this;
		for(var i=0;i<this.total;i++){
			this.items[i]=new TabController.ControlListItem(this.element.children[i],i,controlMethod,function(focusNum){self.parent_focusControl(focusNum);});
		}
	};
	TabController.ControlList.prototype=new FocusList();
	
	//TabControlListItem
	TabController.ControlListItem=function(element,num,controlMethod,parent_focusControl){
		this.element=element;
		this.num=num;
		this.parent_focusControl=parent_focusControl;
		var self=this;
		if(controlMethod=="mouseOver"){
			$(this.element).bind("mouseover",function(ev){self.clickHandler(ev);});
		}else{
			$(this.element).bind("click",function(ev){self.clickHandler(ev);});	
		}
	};
	TabController.ControlListItem.prototype=new FocusListItem();
	TabController.ControlListItem.prototype.clickHandler=function(ev){
		this.parent_focusControl(this.num);
	};
	
	//TabContentList
	TabController.ContentList=function(element){
		this.element=element;
		this.total=this.element.children.length;
		var self=this;
		for(var i=0;i<this.total;i++){
			this.items[i]=new TabController.ContentListItem(this.element.children[i]);
		}
	};
	TabController.ContentList.prototype=new FocusList();
	
	//TabContentListItem
	TabController.ContentListItem=function(element){
		this.element=element;
	};
	TabController.ContentListItem.prototype=new FocusListItem();
	TabController.ContentListItem.prototype.focusOpen=function(){
		this.element.className="tabContent focusOpen";
	};
	TabController.ContentListItem.prototype.focusClose=function(){
		this.element.className="tabContent focusClose";
	};
	module.exports = TabController;
})